package com.gxa.controller.zhy;

import com.gxa.common.R;
import com.gxa.pojo.*;
import com.gxa.pojo.zhy.AdminInformation;
import com.gxa.pojo.zhy.Paging;
import com.gxa.pojo.zhy.Pr;
import com.gxa.service.AdministratorListService;
import com.gxa.utils.MD5Utils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 赵贺益
 * Date: 2021/12/02 17:23
 * Description:
 * Version: V1.0
 */
@Controller
@Api(value ="" ,tags = "系统管理模块接口（管理员列表）4")
@RequestMapping("/system")
public class AdministratorListController {
    @Autowired
    private AdministratorListService administratorListService;


    /**
     * 返回所有的用户（管理员）信息
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/queryAllUsers",method = RequestMethod.GET)
    @ApiOperation(value = "返回所有的用户（管理员）信息的接口(（默认currentPage=1（当前页码），pageSize=10（每页显示的数据））)",notes = "返回的是一个对象List<Users>对象，对象结构如下",httpMethod = "GET", response =Users.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "当前页面显示的数据条数" ,required = true,paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "请求成功"),
            @ApiResponse(code=504,message = "请求失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
//    public List<AdminInformation> queryAllUsers(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,@RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
    public R queryAllUsers(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,@RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){
        R r=administratorListService.queryAllUsers(currentPage,pageSize);
        return r;


    }


    /**
     * 添加管理员
     * @param
     * @param
     * @param
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/addUsers",method = RequestMethod.POST)
    @ApiOperation(value = "添加管理员接口",notes = "返回的是一个对象R，对象结构如下",httpMethod = "POST", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "登录账号" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "user_password",value = "登录密码" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "role_id",value = "角色id，根据上面下拉返回对应的角色id" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "emp_number",value = "员工编号（手动输入，判断该管理员是否已经是员工，是员工才可成为管理员）" ,required = true,paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "添加管理员成功"),
            @ApiResponse(code=504,message = "该账号已经存在，不可重复注册"),
            @ApiResponse(code=503,message = "该员工编号不存在，要先成为员工才能成为管理员"),
            @ApiResponse(code=506,message = "该员工编号已经注册"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })

    public  R addUsers(@RequestBody Users users){
        String username=users.getUsername();
        String user_password= users.getUser_password();


        String emp_number=users.getEmp_number();
        Integer role_id=users.getRole_id();
        R r=administratorListService.addUsers(username,user_password,emp_number,role_id);
        return r;

    }

    /**
     * 查询获取所有的角色，用于下拉框显示
     * @param
     * @param
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/queryAllRolesInsert",method = RequestMethod.GET)
    @ApiOperation(value = "请求获取所有的角色",notes = "返回的是一个R，R对象中的data中存了一个对象List<Role>(集合对象)，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "查询失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R queryAllRoles(){

        R r=administratorListService.queryAllRoles();
        return  r;

    }


    /**
     * 根据管理员的id（user_id）删除管理员
     * @param user_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/delUserbyuser_id",method = RequestMethod.GET)
    @ApiOperation(value = "删除（管理员）信息的接口",notes = "返回的是一个R对象，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id",value = "当前行的管理员的id'" ,required = true,paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "删除成功"),
            @ApiResponse(code=504,message = "删除失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R delUserbyuser_id(Integer user_id){
        R r=administratorListService.delUserbyuser_id(user_id);
        return r;

    }

    /**
     * 键字模糊搜索（管理员）信息的接口
     * @param
     * @return
     */

    @ResponseBody
//    @RequestMapping(value ="/queryAdminInformationByinformation",method = RequestMethod.POST)
    @RequestMapping(value ="/queryAdminInformationByinformation",method = RequestMethod.GET)
    @ApiOperation(value = "关键字模糊搜索（管理员）信息的接口",notes = "返回的是一个R对象，对象结构如下,R的data中存了一个List（AdminInformation）对象，也就是List中装了很多对象",httpMethod = "GET", response =R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "information",value = "搜索框中输入的信息'" ,required = true,paramType = "query"),
//    })
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "查询失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
//    public  R queryAdminInformationByinformation(@RequestBody Paging paging){
    public  R queryAdminInformationByinformation(Integer currentPage,Integer pageSize,String message){
//
//        R r=administratorListService.queryAdminInformationByinformation(paging);
        R r=administratorListService.queryAdminInformationByinformation(currentPage,pageSize,message);
        return r;
    }

    /**
     * 前端返回对应的状态值和管理员id，修改管理员的状态
     * @param user_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/updateUserStatue",method = RequestMethod.GET)
    @ApiOperation(value = "修改（管理员）状态信息的接口",notes = "返回的是一个R对象，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id",value = "当前行的管理员的id'" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "statue",value = "状态id（传1给后端代表解除冻结，传0给后端代表冻结）'" ,required = true,paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "修改状态成功"),
            @ApiResponse(code=504,message = "修改状态失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R updateUserStatue(Integer user_id,Integer statue){
        R r=administratorListService.updateUserStatue(user_id,statue);
        return r;

    }



    /**
     * 对管理员信息进行修改操作
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/updateUsersInformation",method = RequestMethod.POST)
    @ApiOperation(value = "修改用户（管理员）信息的接口",notes = "(界面上没有的数据可以不用传)返回的是R对象，对象结构如下",httpMethod = "POST", response =R.class)

    @ApiResponses({
            @ApiResponse(code=200,message = "修改成功"),
            @ApiResponse(code=504,message = "原密码输入错误，修改失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public  R updateUsersInformation( @RequestBody @ApiParam AdminInformation adminInformation){

        R r=administratorListService.updateUsersInformation(adminInformation);
        return r;



    }


}
